import { EquipInfo } from "../config/JSONDataInterface";
import { GameConst } from "../constant/GameConst";
import Core from "../Core";
import ModelBase, { save } from "./ModelBase";

/**
 * 装备信息（在EquipInfo基础上扩展）
 */
export interface EquipInfoWithExtra extends EquipInfo {
  isOwn: boolean; //是否拥有
  isUsing: boolean; //是否装配
}

/**
 * 装备模型
 */
export default class EquipModel extends ModelBase {
  @save
  public equipMap: Map<string, EquipInfoWithExtra> = new Map();
  public static readonly totalequip: number = 11;
  constructor() {
    super();
  }

  init() {
    console.info("----初始化装备----");
    for (let i = 1; i <= EquipModel.totalequip; i++) {
      let id = GameConst.EQUIP_ID[`EQ_${i}`];
      let cfg = Core.JSONData.equip.get(id);
      console.log(cfg);
      this.equipMap.set(id + "", {
        id: id,
        isOwn: false, //yyyy--仅调试
        isUsing: false,
        ...cfg,
      });
    }
  }

  // 获取装备信息
  getEquipInfo(id: GameConst.EQUIP_ID): EquipInfoWithExtra {
    return this.equipMap.get(id + "");
  }

  //使用装备
  useEquip(info: EquipInfoWithExtra) {}

  //获取已穿戴的装备信息
  getEquipUseInfo(): EquipInfoWithExtra[] {
    let list: EquipInfoWithExtra[] = [];
    for (let i = 1; i <= this.equipMap.size; i++) {
      let equipInfo = this.equipMap.get(GameConst.EQUIP_ID[`EQ_${i}`] + "");
      if (equipInfo.isUsing) {
        list.push(equipInfo);
      }
    }
    return list;
  }

  //装备生效
  applyEquip(info: EquipInfoWithExtra) {}
}
